# ATX headings
An ATX heading (opens new window) consists of a string of characters, parsed as inline content, between an opening sequence of 1–6 unescaped # characters and an optional closing sequence of any number of unescaped # characters. The opening sequence of # characters must be followed by a space (opens new window) or by the end of line. The optional closing sequence of #s must be preceded by a space (opens new window) and may be followed by spaces only. The opening #character may be indented 0-3 spaces. The raw contents of the heading are stripped of leading and trailing spaces before being parsed as inline content. The heading level is equal to the number of # characters in the opening sequence.
Simple headings:
Example 32
| Markdown | HTML | Demo |
|---|---|---|
|
|
More than six # characters is not a heading:
Example 33
| Markdown | HTML | Demo |
|---|---|---|
|
|
At least one space is required between the # characters and the heading’s contents, unless the heading is empty. Note that many implementations currently do not require the space. However, the space was required by the original ATX implementation (opens new window), and it helps prevent things like the following from being parsed as headings:
Example 34
| Markdown | HTML | Demo |
|---|---|---|
|
|
This is not a heading, because the first # is escaped:
Example 35
| Markdown | HTML | Demo |
|---|---|---|
|
|
Contents are parsed as inlines:
Example 36
| Markdown | HTML | Demo |
|---|---|---|
|
|
Leading and trailing whitespace is ignored in parsing inline content:
Example 37
| Markdown | HTML | Demo |
|---|---|---|
|
|
One to three spaces indentation are allowed:
Example 38
| Markdown | HTML | Demo |
|---|---|---|
|
|
Four spaces are too much:
Example 39
| Markdown | HTML | Demo |
|---|---|---|
|
|
Example 40
| Markdown | HTML | Demo |
|---|---|---|
|
|
A closing sequence of # characters is optional:
Example 41
| Markdown | HTML | Demo |
|---|---|---|
|
|
It need not be the same length as the opening sequence:
Example 42
| Markdown | HTML | Demo |
|---|---|---|
|
|
Spaces are allowed after the closing sequence:
Example 43
| Markdown | HTML | Demo |
|---|---|---|
|
|
A sequence of # characters with anything but spaces (opens new window) following it is not a closing sequence, but counts as part of the contents of the heading:
Example 44
| Markdown | HTML | Demo |
|---|---|---|
|
|
The closing sequence must be preceded by a space:
Example 45
| Markdown | HTML | Demo |
|---|---|---|
|
|
Backslash-escaped # characters do not count as part of the closing sequence:
Example 46
| Markdown | HTML | Demo |
|---|---|---|
|
|
ATX headings need not be separated from surrounding content by blank lines, and they can interrupt paragraphs:
Example 47
| Markdown | HTML | Demo |
|---|---|---|
|
|
Example 48
| Markdown | HTML | Demo |
|---|---|---|
|
|
ATX headings can be empty:
Example 49
| Markdown | HTML | Demo |
|---|---|---|
|
|